package com.web.cms.ad.dao;

import com.blue.jdbc.BaseDao;
import com.web.cms.ad.model.Adv;
import org.springframework.stereotype.Repository;

/**
 * 广告数据库访问
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年11月13日
 */
@Repository("adAdvDao")
public class AdvDao extends BaseDao<Adv>
{
	public AdvDao()
	{
	}
	
	@Override
	protected void query(StringBuilder sql, Adv param)
	{
		if (param != null)
		{
			if (param.getWebId() != null && param.getWebId() > 0)
				sql.append(" and a.web_id=:webId");
				
			if (param.getPosId() != null && param.getPosId() > 0)
				sql.append(" and a.pos_id=:posId");
				
			if (param.getName() != null && !param.getName().isEmpty())
			{
				sql.append(" and a.name like :name");
				param.setName("%" + param.getName() + "%");
			}
			
			if (param.getState() != null)
				sql.append(" and a.state=:state");
				
		}
		sql.append(" order by a.id desc");
	}

	@Override
	protected StringBuilder select()
	{
		StringBuilder sql = new StringBuilder(64);
		sql.append("select a.*, p.code pos_code, p.name pos_name, p.type pos_type, w.code web_code from ad_adv a");
		sql.append(" left join ad_adv_pos p on p.id=a.pos_id");
		sql.append(" left join cms_web w on w.id=a.web_id");
		sql.append(" where 1=1");
		return sql;
	}
	
}
